package com.wiley.homePO;

import io.appium.java_client.android.AndroidDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.wiley.publicMethod.BasePage;
import com.wiley.publicMethod.LoggerControler;

import java.net.MalformedURLException;

public class KitchenBiblePage extends BasePage {
	
	LoggerControler log;
	
	/**
	 * 页面元素
	 */
	//厨房宝典  [3]
	public static final By kitchen_bible_loc = By.id(BaseId + "image");
	
	//列表image
	public static final By kitchen_bible_image_loc = By.id(BaseId + "image");
	
	//title
	public static final By title_loc = By.id(BaseId + "title");
	
	//返回
	public static final By back_loc = By.name("转到上一层级");
	
	/**
	 * 操作方法
	 */
	//点击厨房宝典
	public void clickKitchenBible(){
		this.clickEles(kitchen_bible_loc, 3);
	}

	//循环访问image
	public void clickKitchenBibleImage() throws InterruptedException{
		int imageSize = this.getElesLength(kitchen_bible_image_loc);
		for(int i = 0; i < imageSize; i ++){
			try{
				this.clickEles(kitchen_bible_image_loc, i);
				log.info("点击第"+(i+1)+"个image");
				log.info("该title为："+this.getBibleName());
				if(this.isElementPresent(back_loc)){
					this.clickEle(back_loc);
				}
			}catch(Exception e){
				driver.sendKeyEvent(4);
			}
		}
		log.info("当前页面列表访问结束");
	}
	
	//获取title名
	public String getBibleName(){
		WebElement ele = this.findEle(title_loc);
		return ele.getText();
	}
	
	/**
	 * 业务封装
	 * @throws MalformedURLException 
	 * @throws InterruptedException 
	 */
	public void kitchenBibleView(Class name) throws MalformedURLException, InterruptedException  {
		log = this.MyLogger(name);
		AndroidDriver driver = super.SetDriver();
		this.clickKitchenBible();
		log.info("进入厨房宝典");
		this.clickKitchenBibleImage();
		log.info("该case测试通过");
	}
}
